package hotel.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

@Table
@Entity
public class Role {

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int roleid;
	
	@Column(nullable=false)
	private String roleName;
	
	private String comment;
	
	//org.springframework.format.annotation.DateTimeFormat;
	//日期格式转换，如不转换表单带有日期格式时出现Bad Request 400
	//SpringMVC不会自动转换日期格式的数据
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createdTime;

	//角色与权限:多对多关系
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="role_authority",joinColumns=@JoinColumn(name="role_id",referencedColumnName="roleid"),
			inverseJoinColumns=@JoinColumn(name="authority_id",referencedColumnName="authorityid"))
	private List<Authority> authoritys=new ArrayList<Authority>();
	
	public int getRoleid() {
		return roleid;
	}

	public void setRoleid(int roleid) {
		this.roleid = roleid;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public List<Authority> getAuthoritys() {
		return authoritys;
	}

	public void setAuthoritys(List<Authority> authoritys) {
		this.authoritys = authoritys;
	}
	
}
